package io.qar.rawMaterialsConfig.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.qar.commons.mybatis.service.impl.CrudServiceImpl;
import io.qar.commons.tools.utils.ConvertUtils;
import io.qar.rawMaterialsConfig.dao.RawMaterialsConfigDao;
import io.qar.rawMaterialsConfig.dto.RawMaterialsConfigDTO;
import io.qar.rawMaterialsConfig.entity.RawMaterialsConfigEntity;
import io.qar.rawMaterialsConfig.service.RawMaterialsConfigService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 原材料配置表
 *
 * @author yyyyjinying 1020066395@qq.com
 * @since 3.0 2024-07-21
 */
@Service
public class RawMaterialsConfigServiceImpl extends CrudServiceImpl<RawMaterialsConfigDao, RawMaterialsConfigEntity, RawMaterialsConfigDTO> implements RawMaterialsConfigService {

    @Override
    public QueryWrapper<RawMaterialsConfigEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<RawMaterialsConfigEntity> wrapper = new QueryWrapper<>();

        String materialName = (String)params.get("materialName");
        wrapper.eq(StringUtils.isNotBlank(materialName), "material_name", materialName);
        String startDateTime = (String)params.get("startDateTime");
        String endDateTime = (String)params.get("endDateTime");
        wrapper.ge(StringUtils.isNotBlank(startDateTime), "created_at", startDateTime);
        wrapper.le(StringUtils.isNotBlank(endDateTime), "created_at", endDateTime);

        return wrapper;
    }


    @Override
    public List<RawMaterialsConfigDTO> query(Long dishId) {
        List<RawMaterialsConfigEntity> query = baseDao.query(dishId);
        return ConvertUtils.sourceToTarget(query, RawMaterialsConfigDTO.class);
    }

    @Override
    public void deleteMaterials(List<Long> configIds, Long dishId) {
        baseDao.deleteMaterials(configIds, dishId);
    }
}